import request from '@utils/request'
import { APIResult } from '@utils/request/type'
import { Organization } from '@/api/entity/system'
import { ServerEnum } from '@/api/enum/server'
import { UserDTO } from '@/api/entity/user'
import blender from '@yk/components/draw/editor-draw/library/images/modules/blender'

// region TODO 登录
/**
 * 账号密码登录
 * @param params
 */
export const loginByUsernameAPI = (params: {
  // 用户密码
  password: string
  // 用户名
  username: string
  // 30天内自动登录
  autoLogin?: boolean
}) => request.post<APIResult<string>>(ServerEnum.Auth + '/auth/login', params)
// export const loginAPI = (params) => getAxiosResponse({
//   payload: {
//     data: params + 'test_token'
//   }
// })

/**
 * 手机号短信验证码登录
 * @param params
 */
export const loginBySmsAPI = (params: {
  // 手机号
  phone: string
  // 短信code
  smsCode: string
  // 3天内自动登录
  autoLogin?: boolean
}) => request.post<APIResult<string>>(ServerEnum.Auth + '/auth/smsLogin', params)

/**
 * 获取公众号登录二维码
 */
export const getWxQRCodeAPI = () => request.get<APIResult<{
  key: string,
  url: string
}>>(ServerEnum.Auth + '/auth/mp/qrcode')

/**
 * 获取公众号二维码扫码状态。
 * @param params
 * @return data 0：未扫码，1：可登录，2：需注册
 */
export const getScanQRCodesStateAPI = (params: { key: string }) => request.get<APIResult<0|1|2>>(ServerEnum.Auth + '/auth/mp/status/' + params.key)

/**
 * 微信公众号登录
 * @param params
 */
export const loginByWxQRCodeAPI = (params: {
  key: string,
  phone?: string,
  smsCode?: string,
  autoLogin: boolean
}) => request.post(ServerEnum.Auth + '/auth/gzhLogin', params)
// endregion

// region TODO 获取用户信息
export const getUserInfoAPI = () => request.get<APIResult<UserDTO>>(ServerEnum.System + '/sys/user/getLoginUser')
// 模拟获取用户
// export const getUserInfoAPI = () => getAxiosResponse({
//   payload: {
//     id: 1,
//     userName: 'admin',
//     displayName: 'ADMIN_NAME',
//     phone: '18866668888',
//     role: '0'
//   } as User
// })
// endregion

/**
 * 注册
 * @param params
 */
export const registerUserAPI = (params: {
  // 确认密码
  confirmPassword: string
  // 姓名
  nickName: string
  // 用户密码
  password: string
  // 手机号
  phone: string
  // 短信code
  smsCode: string
  // 用户名
  username: string
}) => request.post(ServerEnum.Auth + '/auth/register', params)

/**
 * 发送短信验证码
 * @param params
 */
export const sendNoteCodeAPI = (params: {
  // 手机号
  phone: string,
  // 类型 0-登录 1-注册 2-忘记密码 3-修改手机号 4-修改密码 5-公众号注册
  type: number
}) => request.get(ServerEnum.Auth + '/auth/code', { params })

/**
 * 忘记密码
 * @param params
 */
export const forgotPasswordAPI = (params: {
  // 确认密码
  confirmPassword: string
  // 用户密码
  password: string
  // 手机号
  phone: string
  // 短信code
  smsCode: string
}) => request.post(ServerEnum.Auth + '/auth/forgotPassword', params)

/**
 * 修改手机号
 * @param params
 */
export const updatePhoneAPI = (params: {
  // 手机号
  newPhone: string
  // 手机号
  oldPhone: string
  // 短信code
  smsCode: string
}) => request.post(ServerEnum.Auth + '/auth/updatePhone', params)

/**
 * 修改密码
 * @param params
 */
export const updatePasswordAPI = (params: {
  // 短信code类型
  codeType?: number
  // 确认密码
  confirmPassword: string
  // 密码
  password: string
  // 手机号
  phone: string
  // 短信code
  smsCode: string
}) => request.post(ServerEnum.Auth + '/auth/updatePassword', params)

/**
 * 修改当前用户
 * @param params
 */
export const updateCurrentUserAPI = (params: UserDTO) => request.post(ServerEnum.System + '/sys/user/editLoginUser', params)

/**
 * 修改头像
 * @param params
 */
export const updateAvatarAPI = (params: { avatar: string }) => updateCurrentUserAPI({ avatar: params.avatar })

/**
 * 检查引导 true-已执行
 * @param params
 */
export const checkTourStepAPI = (params: { userId: string }) => request.get<APIResult<boolean>>(ServerEnum.System + '/sys/user/steer/' + params.userId)
